package com.codegeek.project.slope.controller;

import com.codegeek.common.utils.poi.ExcelUtil;
import com.codegeek.framework.aspectj.lang.annotation.Log;
import com.codegeek.framework.aspectj.lang.enums.BusinessType;
import com.codegeek.framework.web.controller.BaseController;
import com.codegeek.framework.web.domain.AjaxResult;
import com.codegeek.framework.web.page.TableDataInfo;
import com.codegeek.project.slope.domain.SlopeUnit;
import com.codegeek.project.slope.service.ISlopeUnitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 行政单位Controller
 *
 * @author codegeek
 * @date 2020-02-17
 */
@RestController
@RequestMapping("/slope/unit")
@Api(value = "行政单位Controller", tags = {"行政单位操作接口"})
public class SlopeUnitController extends BaseController {
    @Autowired
    private ISlopeUnitService slopeUnitService;

    /**
     * 查询行政单位列表
     */
    @ApiOperation("查询行政单位列表")
    @GetMapping("/list")
    public TableDataInfo list(SlopeUnit slopeUnit) {
        startPage();
        List<SlopeUnit> list = slopeUnitService.selectSlopeUnitList(slopeUnit);
        return getDataTable(list);
    }

    /**
     * 导出行政单位列表
     */
    @ApiOperation("导出行政单位列表")
    @Log(title = "行政单位", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SlopeUnit slopeUnit) {
        List<SlopeUnit> list = slopeUnitService.selectSlopeUnitList(slopeUnit);
        ExcelUtil<SlopeUnit> util = new ExcelUtil<SlopeUnit>(SlopeUnit.class);
        return util.exportExcel(list, "unit");
    }

    /**
     * 获取行政单位详细信息
     */
    @ApiOperation("获取行政单位详细信息")
    @GetMapping(value = "/getInfo/{unitId}")
    public AjaxResult getInfo(@PathVariable("unitId") Long unitId) {
        return AjaxResult.success(slopeUnitService.selectSlopeUnitById(unitId));
    }

    /**
     * 新增行政单位
     */
    @ApiOperation("新增行政单位")
    @Log(title = "行政单位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SlopeUnit slopeUnit) {
        return toAjax(slopeUnitService.insertSlopeUnit(slopeUnit));
    }

    /**
     * 修改行政单位
     */
    @ApiOperation("修改行政单位")
    @Log(title = "行政单位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SlopeUnit slopeUnit) {
        return toAjax(slopeUnitService.updateSlopeUnit(slopeUnit));
    }

    /**
     * 删除行政单位
     */
    @ApiOperation("删除行政单位")
    @Log(title = "行政单位", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{unitIds}")
    public AjaxResult remove(@PathVariable Long[] unitIds) {
        return toAjax(slopeUnitService.deleteSlopeUnitByIds(unitIds));
    }
}
